from selenium.webdriver.common.by import By


class Buy():

    def __init__(self, driver):
        self.driver = driver

    def buy(self, payword, xpath1, xpath2):
        # 点击个人理财
        self.driver.find_element(By.XPATH, '/html/body/div/div/aside/div[2]/nav/ul/li[2]/a').click()
        # 点击零钱理财
        self.driver.find_element(By.XPATH, xpath1).click()
        # 点击投资
        self.driver.find_element(By.XPATH, xpath2).click()
        # 输入支付密码
        self.driver.find_element(By.XPATH, '/html/body/div[3]/div[2]/input').send_keys(payword)
        # 点击确定
        self.driver.find_element(By.XPATH, '/html/body/div[3]/div[3]/a[1]').click()

    def check(self):
        # 点击个人中心
        self.driver.find_element(By.XPATH, '/html/body/div/div/aside/div[2]/nav/ul/li[4]/a').click()
        # 点击银行卡管理
        self.driver.find_element(By.XPATH, '/html/body/div/div/aside/div[2]/nav/ul/li[4]/ul/li[3]/a').click()
        # 查看信用卡余额
        text = self.driver.find_element(By.XPATH,
                                 '/html/body/div/div/main/div/div/div[2]/div/div/div[2]/h4[2]').text
        return text[5:-1]